package homework;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class zy5 {
	public static void main(String[] args) throws IOException {
		sortFile("writer.txt");
	}	
	
	public static void sortFile(String source) throws IOException{
		FileReader fr=new FileReader(source);
		StringBuffer stringBuffer =new StringBuffer();
		int ch=0;
		while((ch=fr.read())!=-1){
			stringBuffer.append((char)ch);
		}
		List<Integer> collect = Arrays.stream(stringBuffer.toString().split("-")).map(Integer::parseInt)	
			.sorted().collect(Collectors.toList());
		FileWriter fw=new FileWriter(source);
		System.out.println(collect);
		for(int i=0;i<collect.size();i++){
			if(i<collect.size()-1){
				fw.write(String.valueOf(collect.get(i)));
				fw.write('-');
			}else{
				fw.write(String.valueOf(collect.get(i)));
			}
		}
		fw.close();
		fr.close();
	}
}
